<?php
declare (strict_types = 1);

namespace app\attachment\controller;
use app\common\controller\AppBase;
use think\facade\Env;
class Base extends AppBase
{
    // 是否记录日志
    public $save_log = true; 
    protected function initialize()
    {
        parent::initialize();
        $this->model = new \app\common\model\Attachment;
    }
    // 获取服务地址
    protected function get_server_url($path)
    {
        $host = Env::get('app.host', '');
        if(empty($host)) {
            return ($this->is_https() ? "https://" : "http://").$_SERVER['HTTP_HOST'].$path;
        }else{
            return ($this->is_https() ? "https://" : "http://").$host.'/'.$path;
        }
    }
    
    // 判断请求链接是否为https
    protected function is_https() 
    {
        if ( !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
            return true;
        } elseif ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
            return true;
        } elseif ( !empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
            return true;
        }
        return false;
    }
}
